package com.example.user.config;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 统一封装结果集
 *
 * @author SunBin
 * @version $Id$
 * @since 2022年2月25日 上午11:09:08
 */
@Getter
@Setter
@SuppressWarnings("ALL")
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

    private static final String SUCCESS_CODE = "000000";
    private static final String ERROR_CODE = "999999";

    private T resultObj;
    private String resultCode;
    private String resultMsg;

    public static <T> Result<T> succeed(String msg) {
        return succeedWith(null, SUCCESS_CODE, msg);
    }

    public static <T> Result<T> succeed(T model, String msg) {
        return succeedWith(model, SUCCESS_CODE, msg);
    }

    public static <T> Result<T> succeed(T model) {
        return succeedWith(model, SUCCESS_CODE, "");
    }

    public static <T> Result<T> succeedWith(T datas, String code, String msg) {
        return new Result<>(datas, code, msg);
    }

    public static <T> Result<T> of(T datas, String code, String msg) {
        return new Result<>(datas, code, msg);
    }

    /*public static <T> com.ifugle.rap.cpzx.sjzs.config.Result<T> failed(String msg, String respCode) {

        return failedWith(null, respCode, msg);
        //        if (respCode > 0) {
        //            return failedWith(null, respCode, msg);
        //        }
        //        return failedWith(null, CodeEnum.ERROR.getCode(), msg);
    }*/

    public static <T> Result<T> failed(String code,String msg) {
        return failedWith(null, ERROR_CODE, msg);
    }

    public static <T> Result<T> failedWith(T model, String msg) {
        return failedWith(model, ERROR_CODE, msg);
    }

    public static <T> Result<T> failedWith(T datas, String code, String msg) {
        return new Result<>(datas, code, msg);
    }

}
